package servicesImp.business;

import base.IBaseMapperWithoutBLOBs;
import base.IBaseServicesWithoutBLOBsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.business.BusinessInfoServices;
import services.business.InspectorInfoServices;
import services.business.ObserverAssessServices;
import wt.dao.business.ObserverAssessMapper;
import wt.entity.business.BusinessInfo;
import wt.entity.business.ObserverAssess;
import wt.entity.business.ObserverAssessExample;
import wt.staticData.ShortData;
import wt.staticData.TableName;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class ObserverAssessServicesImp extends IBaseServicesWithoutBLOBsImpl< ObserverAssess, ObserverAssessExample> implements ObserverAssessServices {
    @Autowired
    ObserverAssessMapper observerAssessMapper;
    @Autowired
    BusinessInfoServices businessInfoServices;
    @Autowired
    InspectorInfoServices inspectorInfoServices;

    @Override
    public IBaseMapperWithoutBLOBs< ObserverAssess, ObserverAssessExample> getMapper() {
        return this.observerAssessMapper;
    }

    @Override
    public String getTableName() {
        return TableName.BUS_OBSERVER_ASSESS;
    }

    @Transactional
    public void insertSelective(List<ObserverAssess> observerAssessList, String businessId) throws Exception {
        BusinessInfo businessInfo = new BusinessInfo();
        businessInfo.setId(businessId);
        businessInfo.setObserverIsAssess(ShortData.s1);
        businessInfo.setObserverAssessTime(new Date());
        businessInfoServices.updateByPrimaryKeySelective(businessInfo);

        for (ObserverAssess observerAssess : observerAssessList) {
            observerAssess.setBusinessId(businessId);
            getCurrentProxy().insertSelective(observerAssess);
        }


    }

    public void lazyLoadInspectorInfo(List<ObserverAssess> observerAssessList) throws Exception {
        if (observerAssessList != null) {
            for (ObserverAssess observerAssess : observerAssessList) {
                observerAssess.setInspectorInfo(inspectorInfoServices.selectByPrimaryKey(observerAssess.getInspectorId()));
            }
        }
    }
}
